package com.ims.word;

import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.xwpf.usermodel.*;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 创建word
 * @author gaoxu
 * @date 2019-07-04 17:31
 */
public class X01CreateWord {

    public static void main(String[] args) {

        try {
            /**
             * 97-2007
             */
           /* // 创建新的工作簿
            Workbook wb = new HSSFWorkbook();
            // 创建新的Sheet页
            Sheet sheet1 = wb.createSheet("第一个Sheet页");
            Sheet sheet2 = wb.createSheet("第二个Sheet页");
            // 在指定位置写入工作簿
            OutputStream fileOut = new FileOutputStream("hellExcel97-2007.doc");
            wb.write(fileOut);
            fileOut.close();*/

            /**
             * 2007
             */
            //创建doc
            XWPFDocument doc = new XWPFDocument();
            OutputStream fileOut = new FileOutputStream("hellWord2007.docx");
            //段落
            XWPFParagraph paragraph = doc.createParagraph();
            XWPFRun run = paragraph.createRun();
            run.setText("Java POI 生成word文件。");
            run.setColor("696969");
            run.setFontSize(16);
            //输出doc
            doc.write(fileOut);
            fileOut.close();

        } catch (IOException e) {
            e.printStackTrace();
        }


    }
}
